1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module glib.Source; 26 27 private import glib.ConstructionException; 28 private import glib.MainContext; 29 private import glib.Str; 30 private import glib.TimeVal; 31 private import glib.c.functions; 32 public import glib.c.types; 33 private import linker.Loader; 34 35 36 /** 37 * The `GSource` struct is an opaque data type 38 * representing an event source. 39 */ 40 public class Source 41 { 42 /** the main Gtk struct */ 43 protected GSource* gSource; 44 protected bool ownedRef; 45 46 /** Get the main Gtk struct */ 47 public GSource* getSourceStruct(bool transferOwnership = false) 48 { 49 if (transferOwnership) 50 ownedRef = false; 51 return gSource; 52 } 53 54 /** the main Gtk struct as a void* */ 55 protected void* getStruct() 56 { 57 return cast(void*)gSource; 58 } 59 60 /** 61 * Sets our main struct and passes it to the parent class. 62 */ 63 public this (GSource* gSource, bool ownedRef = false) 64 { 65 this.gSource = gSource; 66 this.ownedRef = ownedRef; 67 } 68 69 ~this () 70 { 71 if ( Linker.isLoaded(LIBRARY_GLIB[0]) && ownedRef ) 72 g_source_unref(gSource); 73 } 74 75 76 /** 77 * Creates a new #GSource structure. The size is specified to 78 * allow creating structures derived from #GSource that contain 79 * additional data. The size passed in must be at least 80 * `sizeof (GSource)`. 81 * 82 * The source will not initially be associated with any #GMainContext 83 * and must be added to one with g_source_attach() before it will be 84 * executed. 85 * 86 * Params: 87 * sourceFuncs = structure containing functions that implement 88 * the sources behavior. 89 * structSize = size of the #GSource structure to create. 90 * 91 * Returns: the newly-created #GSource. 92 * 93 * Throws: ConstructionException GTK+ fails to create the object. 94 */ 95 public this(GSourceFuncs* sourceFuncs, uint structSize) 96 { 97 auto __p = g_source_new(sourceFuncs, structSize); 98 99 if(__p is null) 100 { 101 throw new ConstructionException("null returned by new"); 102 } 103 104 this(cast(GSource*) __p); 105 } 106 107 /** 108 * Adds @child_source to @source as a "polled" source; when @source is 109 * added to a #GMainContext, @child_source will be automatically added 110 * with the same priority, when @child_source is triggered, it will 111 * cause @source to dispatch (in addition to calling its own 112 * callback), and when @source is destroyed, it will destroy 113 * @child_source as well. (@source will also still be dispatched if 114 * its own prepare/check functions indicate that it is ready.) 115 * 116 * If you don't need @child_source to do anything on its own when it 117 * triggers, you can call g_source_set_dummy_callback() on it to set a 118 * callback that does nothing (except return %TRUE if appropriate). 119 * 120 * @source will hold a reference on @child_source while @child_source 121 * is attached to it. 122 * 123 * This API is only intended to be used by implementations of #GSource. 124 * Do not call this API on a #GSource that you did not create. 125 * 126 * Params: 127 * childSource = a second #GSource that @source should "poll" 128 * 129 * Since: 2.28 130 */ 131 public void addChildSource(Source childSource) 132 { 133 g_source_add_child_source(gSource, (childSource is null) ? null : childSource.getSourceStruct()); 134 } 135 136 /** 137 * Adds a file descriptor to the set of file descriptors polled for 138 * this source. This is usually combined with g_source_new() to add an 139 * event source. The event source's check function will typically test 140 * the @revents field in the #GPollFD struct and return %TRUE if events need 141 * to be processed. 142 * 143 * This API is only intended to be used by implementations of #GSource. 144 * Do not call this API on a #GSource that you did not create. 145 * 146 * Using this API forces the linear scanning of event sources on each 147 * main loop iteration. Newly-written event sources should try to use 148 * g_source_add_unix_fd() instead of this API. 149 * 150 * Params: 151 * fd = a #GPollFD structure holding information about a file 152 * descriptor to watch. 153 */ 154 public void addPoll(GPollFD* fd) 155 { 156 g_source_add_poll(gSource, fd); 157 } 158 159 /** 160 * Monitors @fd for the IO events in @events. 161 * 162 * The tag returned by this function can be used to remove or modify the 163 * monitoring of the fd using g_source_remove_unix_fd() or 164 * g_source_modify_unix_fd(). 165 * 166 * It is not necessary to remove the fd before destroying the source; it 167 * will be cleaned up automatically. 168 * 169 * This API is only intended to be used by implementations of #GSource. 170 * Do not call this API on a #GSource that you did not create. 171 * 172 * As the name suggests, this function is not available on Windows. 173 * 174 * Params: 175 * fd = the fd to monitor 176 * events = an event mask 177 * 178 * Returns: an opaque tag 179 * 180 * Since: 2.36 181 */ 182 public void* addUnixFd(int fd, GIOCondition events) 183 { 184 return g_source_add_unix_fd(gSource, fd, events); 185 } 186 187 /** 188 * Adds a #GSource to a @context so that it will be executed within 189 * that context. Remove it by calling g_source_destroy(). 190 * 191 * This function is safe to call from any thread, regardless of which thread 192 * the @context is running in. 193 * 194 * Params: 195 * context = a #GMainContext (if %NULL, the default context will be used) 196 * 197 * Returns: the ID (greater than 0) for the source within the 198 * #GMainContext. 199 */ 200 public uint attach(MainContext context) 201 { 202 return g_source_attach(gSource, (context is null) ? null : context.getMainContextStruct()); 203 } 204 205 /** 206 * Removes a source from its #GMainContext, if any, and mark it as 207 * destroyed. The source cannot be subsequently added to another 208 * context. It is safe to call this on sources which have already been 209 * removed from their context. 210 * 211 * This does not unref the #GSource: if you still hold a reference, use 212 * g_source_unref() to drop it. 213 * 214 * This function is safe to call from any thread, regardless of which thread 215 * the #GMainContext is running in. 216 * 217 * If the source is currently attached to a #GMainContext, destroying it 218 * will effectively unset the callback similar to calling g_source_set_callback(). 219 * This can mean, that the data's #GDestroyNotify gets called right away. 220 */ 221 public void destroy() 222 { 223 g_source_destroy(gSource); 224 } 225 226 /** 227 * Checks whether a source is allowed to be called recursively. 228 * see g_source_set_can_recurse(). 229 * 230 * Returns: whether recursion is allowed. 231 */ 232 public bool getCanRecurse() 233 { 234 return g_source_get_can_recurse(gSource) != 0; 235 } 236 237 /** 238 * Gets the #GMainContext with which the source is associated. 239 * 240 * You can call this on a source that has been destroyed, provided 241 * that the #GMainContext it was attached to still exists (in which 242 * case it will return that #GMainContext). In particular, you can 243 * always call this function on the source returned from 244 * g_main_current_source(). But calling this function on a source 245 * whose #GMainContext has been destroyed is an error. 246 * 247 * Returns: the #GMainContext with which the 248 * source is associated, or %NULL if the context has not 249 * yet been added to a source. 250 */ 251 public MainContext getContext() 252 { 253 auto __p = g_source_get_context(gSource); 254 255 if(__p is null) 256 { 257 return null; 258 } 259 260 return new MainContext(cast(GMainContext*) __p); 261 } 262 263 /** 264 * This function ignores @source and is otherwise the same as 265 * g_get_current_time(). 266 * 267 * Deprecated: use g_source_get_time() instead 268 * 269 * Params: 270 * timeval = #GTimeVal structure in which to store current time. 271 */ 272 public void getCurrentTime(TimeVal timeval) 273 { 274 g_source_get_current_time(gSource, (timeval is null) ? null : timeval.getTimeValStruct()); 275 } 276 277 /** 278 * Returns the numeric ID for a particular source. The ID of a source 279 * is a positive integer which is unique within a particular main loop 280 * context. The reverse 281 * mapping from ID to source is done by g_main_context_find_source_by_id(). 282 * 283 * You can only call this function while the source is associated to a 284 * #GMainContext instance; calling this function before g_source_attach() 285 * or after g_source_destroy() yields undefined behavior. The ID returned 286 * is unique within the #GMainContext instance passed to g_source_attach(). 287 * 288 * Returns: the ID (greater than 0) for the source 289 */ 290 public uint getId() 291 { 292 return g_source_get_id(gSource); 293 } 294 295 /** 296 * Gets a name for the source, used in debugging and profiling. The 297 * name may be #NULL if it has never been set with g_source_set_name(). 298 * 299 * Returns: the name of the source 300 * 301 * Since: 2.26 302 */ 303 public string getName() 304 { 305 return Str.toString(g_source_get_name(gSource)); 306 } 307 308 /** 309 * Gets the priority of a source. 310 * 311 * Returns: the priority of the source 312 */ 313 public int getPriority() 314 { 315 return g_source_get_priority(gSource); 316 } 317 318 /** 319 * Gets the "ready time" of @source, as set by 320 * g_source_set_ready_time(). 321 * 322 * Any time before the current monotonic time (including 0) is an 323 * indication that the source will fire immediately. 324 * 325 * Returns: the monotonic ready time, -1 for "never" 326 */ 327 public long getReadyTime() 328 { 329 return g_source_get_ready_time(gSource); 330 } 331 332 /** 333 * Gets the time to be used when checking this source. The advantage of 334 * calling this function over calling g_get_monotonic_time() directly is 335 * that when checking multiple sources, GLib can cache a single value 336 * instead of having to repeatedly get the system monotonic time. 337 * 338 * The time here is the system monotonic time, if available, or some 339 * other reasonable alternative otherwise. See g_get_monotonic_time(). 340 * 341 * Returns: the monotonic time in microseconds 342 * 343 * Since: 2.28 344 */ 345 public long getTime() 346 { 347 return g_source_get_time(gSource); 348 } 349 350 /** 351 * Returns whether @source has been destroyed. 352 * 353 * This is important when you operate upon your objects 354 * from within idle handlers, but may have freed the object 355 * before the dispatch of your idle handler. 356 * 357 * |[<!-- language="C" --> 358 * static gboolean 359 * idle_callback (gpointer data) 360 * { 361 * SomeWidget *self = data; 362 * 363 * g_mutex_lock (&self->idle_id_mutex); 364 * // do stuff with self 365 * self->idle_id = 0; 366 * g_mutex_unlock (&self->idle_id_mutex); 367 * 368 * return G_SOURCE_REMOVE; 369 * } 370 * 371 * static void 372 * some_widget_do_stuff_later (SomeWidget *self) 373 * { 374 * g_mutex_lock (&self->idle_id_mutex); 375 * self->idle_id = g_idle_add (idle_callback, self); 376 * g_mutex_unlock (&self->idle_id_mutex); 377 * } 378 * 379 * static void 380 * some_widget_init (SomeWidget *self) 381 * { 382 * g_mutex_init (&self->idle_id_mutex); 383 * 384 * // ... 385 * } 386 * 387 * static void 388 * some_widget_finalize (GObject *object) 389 * { 390 * SomeWidget *self = SOME_WIDGET (object); 391 * 392 * if (self->idle_id) 393 * g_source_remove (self->idle_id); 394 * 395 * g_mutex_clear (&self->idle_id_mutex); 396 * 397 * G_OBJECT_CLASS (parent_class)->finalize (object); 398 * } 399 * ]| 400 * 401 * This will fail in a multi-threaded application if the 402 * widget is destroyed before the idle handler fires due 403 * to the use after free in the callback. A solution, to 404 * this particular problem, is to check to if the source 405 * has already been destroy within the callback. 406 * 407 * |[<!-- language="C" --> 408 * static gboolean 409 * idle_callback (gpointer data) 410 * { 411 * SomeWidget *self = data; 412 * 413 * g_mutex_lock (&self->idle_id_mutex); 414 * if (!g_source_is_destroyed (g_main_current_source ())) 415 * { 416 * // do stuff with self 417 * } 418 * g_mutex_unlock (&self->idle_id_mutex); 419 * 420 * return FALSE; 421 * } 422 * ]| 423 * 424 * Calls to this function from a thread other than the one acquired by the 425 * #GMainContext the #GSource is attached to are typically redundant, as the 426 * source could be destroyed immediately after this function returns. However, 427 * once a source is destroyed it cannot be un-destroyed, so this function can be 428 * used for opportunistic checks from any thread. 429 * 430 * Returns: %TRUE if the source has been destroyed 431 * 432 * Since: 2.12 433 */ 434 public bool isDestroyed() 435 { 436 return g_source_is_destroyed(gSource) != 0; 437 } 438 439 /** 440 * Updates the event mask to watch for the fd identified by @tag. 441 * 442 * @tag is the tag returned from g_source_add_unix_fd(). 443 * 444 * If you want to remove a fd, don't set its event mask to zero. 445 * Instead, call g_source_remove_unix_fd(). 446 * 447 * This API is only intended to be used by implementations of #GSource. 448 * Do not call this API on a #GSource that you did not create. 449 * 450 * As the name suggests, this function is not available on Windows. 451 * 452 * Params: 453 * tag = the tag from g_source_add_unix_fd() 454 * newEvents = the new event mask to watch 455 * 456 * Since: 2.36 457 */ 458 public void modifyUnixFd(void* tag, GIOCondition newEvents) 459 { 460 g_source_modify_unix_fd(gSource, tag, newEvents); 461 } 462 463 /** 464 * Queries the events reported for the fd corresponding to @tag on 465 * @source during the last poll. 466 * 467 * The return value of this function is only defined when the function 468 * is called from the check or dispatch functions for @source. 469 * 470 * This API is only intended to be used by implementations of #GSource. 471 * Do not call this API on a #GSource that you did not create. 472 * 473 * As the name suggests, this function is not available on Windows. 474 * 475 * Params: 476 * tag = the tag from g_source_add_unix_fd() 477 * 478 * Returns: the conditions reported on the fd 479 * 480 * Since: 2.36 481 */ 482 public GIOCondition queryUnixFd(void* tag) 483 { 484 return g_source_query_unix_fd(gSource, tag); 485 } 486 487 alias doref = ref_; 488 /** 489 * Increases the reference count on a source by one. 490 * 491 * Returns: @source 492 */ 493 public Source ref_() 494 { 495 auto __p = g_source_ref(gSource); 496 497 if(__p is null) 498 { 499 return null; 500 } 501 502 return new Source(cast(GSource*) __p, true); 503 } 504 505 /** 506 * Detaches @child_source from @source and destroys it. 507 * 508 * This API is only intended to be used by implementations of #GSource. 509 * Do not call this API on a #GSource that you did not create. 510 * 511 * Params: 512 * childSource = a #GSource previously passed to 513 * g_source_add_child_source(). 514 * 515 * Since: 2.28 516 */ 517 public void removeChildSource(Source childSource) 518 { 519 g_source_remove_child_source(gSource, (childSource is null) ? null : childSource.getSourceStruct()); 520 } 521 522 /** 523 * Removes a file descriptor from the set of file descriptors polled for 524 * this source. 525 * 526 * This API is only intended to be used by implementations of #GSource. 527 * Do not call this API on a #GSource that you did not create. 528 * 529 * Params: 530 * fd = a #GPollFD structure previously passed to g_source_add_poll(). 531 */ 532 public void removePoll(GPollFD* fd) 533 { 534 g_source_remove_poll(gSource, fd); 535 } 536 537 /** 538 * Reverses the effect of a previous call to g_source_add_unix_fd(). 539 * 540 * You only need to call this if you want to remove an fd from being 541 * watched while keeping the same source around. In the normal case you 542 * will just want to destroy the source. 543 * 544 * This API is only intended to be used by implementations of #GSource. 545 * Do not call this API on a #GSource that you did not create. 546 * 547 * As the name suggests, this function is not available on Windows. 548 * 549 * Params: 550 * tag = the tag from g_source_add_unix_fd() 551 * 552 * Since: 2.36 553 */ 554 public void removeUnixFd(void* tag) 555 { 556 g_source_remove_unix_fd(gSource, tag); 557 } 558 559 /** 560 * Sets the callback function for a source. The callback for a source is 561 * called from the source's dispatch function. 562 * 563 * The exact type of @func depends on the type of source; ie. you 564 * should not count on @func being called with @data as its first 565 * parameter. Cast @func with G_SOURCE_FUNC() to avoid warnings about 566 * incompatible function types. 567 * 568 * See [memory management of sources][mainloop-memory-management] for details 569 * on how to handle memory management of @data. 570 * 571 * Typically, you won't use this function. Instead use functions specific 572 * to the type of source you are using, such as g_idle_add() or g_timeout_add(). 573 * 574 * It is safe to call this function multiple times on a source which has already 575 * been attached to a context. The changes will take effect for the next time 576 * the source is dispatched after this call returns. 577 * 578 * Note that g_source_destroy() for a currently attached source has the effect 579 * of also unsetting the callback. 580 * 581 * Params: 582 * func = a callback function 583 * data = the data to pass to callback function 584 * notify = a function to call when @data is no longer in use, or %NULL. 585 */ 586 public void setCallback(GSourceFunc func, void* data, GDestroyNotify notify) 587 { 588 g_source_set_callback(gSource, func, data, notify); 589 } 590 591 /** 592 * Sets the callback function storing the data as a refcounted callback 593 * "object". This is used internally. Note that calling 594 * g_source_set_callback_indirect() assumes 595 * an initial reference count on @callback_data, and thus 596 * @callback_funcs->unref will eventually be called once more 597 * than @callback_funcs->ref. 598 * 599 * It is safe to call this function multiple times on a source which has already 600 * been attached to a context. The changes will take effect for the next time 601 * the source is dispatched after this call returns. 602 * 603 * Params: 604 * callbackData = pointer to callback data "object" 605 * callbackFuncs = functions for reference counting @callback_data 606 * and getting the callback and data 607 */ 608 public void setCallbackIndirect(void* callbackData, GSourceCallbackFuncs* callbackFuncs) 609 { 610 g_source_set_callback_indirect(gSource, callbackData, callbackFuncs); 611 } 612 613 /** 614 * Sets whether a source can be called recursively. If @can_recurse is 615 * %TRUE, then while the source is being dispatched then this source 616 * will be processed normally. Otherwise, all processing of this 617 * source is blocked until the dispatch function returns. 618 * 619 * Params: 620 * canRecurse = whether recursion is allowed for this source 621 */ 622 public void setCanRecurse(bool canRecurse) 623 { 624 g_source_set_can_recurse(gSource, canRecurse); 625 } 626 627 /** 628 * Set @dispose as dispose function on @source. @dispose will be called once 629 * the reference count of @source reaches 0 but before any of the state of the 630 * source is freed, especially before the finalize function is called. 631 * 632 * This means that at this point @source is still a valid #GSource and it is 633 * allow for the reference count to increase again until @dispose returns. 634 * 635 * The dispose function can be used to clear any "weak" references to the 636 * @source in other data structures in a thread-safe way where it is possible 637 * for another thread to increase the reference count of @source again while 638 * it is being freed. 639 * 640 * The finalize function can not be used for this purpose as at that point 641 * @source is already partially freed and not valid anymore. 642 * 643 * This should only ever be called from #GSource implementations. 644 * 645 * Params: 646 * dispose = #GSourceDisposeFunc to set on the source 647 * 648 * Since: 2.64 649 */ 650 public void setDisposeFunction(GSourceDisposeFunc dispose) 651 { 652 g_source_set_dispose_function(gSource, dispose); 653 } 654 655 /** 656 * Sets the source functions (can be used to override 657 * default implementations) of an unattached source. 658 * 659 * Params: 660 * funcs = the new #GSourceFuncs 661 * 662 * Since: 2.12 663 */ 664 public void setFuncs(GSourceFuncs* funcs) 665 { 666 g_source_set_funcs(gSource, funcs); 667 } 668 669 /** 670 * Sets a name for the source, used in debugging and profiling. 671 * The name defaults to #NULL. 672 * 673 * The source name should describe in a human-readable way 674 * what the source does. For example, "X11 event queue" 675 * or "GTK+ repaint idle handler" or whatever it is. 676 * 677 * It is permitted to call this function multiple times, but is not 678 * recommended due to the potential performance impact. For example, 679 * one could change the name in the "check" function of a #GSourceFuncs 680 * to include details like the event type in the source name. 681 * 682 * Use caution if changing the name while another thread may be 683 * accessing it with g_source_get_name(); that function does not copy 684 * the value, and changing the value will free it while the other thread 685 * may be attempting to use it. 686 * 687 * Also see g_source_set_static_name(). 688 * 689 * Params: 690 * name = debug name for the source 691 * 692 * Since: 2.26 693 */ 694 public void setName(string name) 695 { 696 g_source_set_name(gSource, Str.toStringz(name)); 697 } 698 699 /** 700 * Sets the priority of a source. While the main loop is being run, a 701 * source will be dispatched if it is ready to be dispatched and no 702 * sources at a higher (numerically smaller) priority are ready to be 703 * dispatched. 704 * 705 * A child source always has the same priority as its parent. It is not 706 * permitted to change the priority of a source once it has been added 707 * as a child of another source. 708 * 709 * Params: 710 * priority = the new priority. 711 */ 712 public void setPriority(int priority) 713 { 714 g_source_set_priority(gSource, priority); 715 } 716 717 /** 718 * Sets a #GSource to be dispatched when the given monotonic time is 719 * reached (or passed). If the monotonic time is in the past (as it 720 * always will be if @ready_time is 0) then the source will be 721 * dispatched immediately. 722 * 723 * If @ready_time is -1 then the source is never woken up on the basis 724 * of the passage of time. 725 * 726 * Dispatching the source does not reset the ready time. You should do 727 * so yourself, from the source dispatch function. 728 * 729 * Note that if you have a pair of sources where the ready time of one 730 * suggests that it will be delivered first but the priority for the 731 * other suggests that it would be delivered first, and the ready time 732 * for both sources is reached during the same main context iteration, 733 * then the order of dispatch is undefined. 734 * 735 * It is a no-op to call this function on a #GSource which has already been 736 * destroyed with g_source_destroy(). 737 * 738 * This API is only intended to be used by implementations of #GSource. 739 * Do not call this API on a #GSource that you did not create. 740 * 741 * Params: 742 * readyTime = the monotonic time at which the source will be ready, 743 * 0 for "immediately", -1 for "never" 744 * 745 * Since: 2.36 746 */ 747 public void setReadyTime(long readyTime) 748 { 749 g_source_set_ready_time(gSource, readyTime); 750 } 751 752 /** 753 * A variant of g_source_set_name() that does not 754 * duplicate the @name, and can only be used with 755 * string literals. 756 * 757 * Params: 758 * name = debug name for the source 759 * 760 * Since: 2.70 761 */ 762 public void setStaticName(string name) 763 { 764 g_source_set_static_name(gSource, Str.toStringz(name)); 765 } 766 767 /** 768 * Decreases the reference count of a source by one. If the 769 * resulting reference count is zero the source and associated 770 * memory will be destroyed. 771 */ 772 public void unref() 773 { 774 g_source_unref(gSource); 775 } 776 777 /** 778 * Removes the source with the given ID from the default main context. You must 779 * use g_source_destroy() for sources added to a non-default main context. 780 * 781 * The ID of a #GSource is given by g_source_get_id(), or will be 782 * returned by the functions g_source_attach(), g_idle_add(), 783 * g_idle_add_full(), g_timeout_add(), g_timeout_add_full(), 784 * g_child_watch_add(), g_child_watch_add_full(), g_io_add_watch(), and 785 * g_io_add_watch_full(). 786 * 787 * It is a programmer error to attempt to remove a non-existent source. 788 * 789 * More specifically: source IDs can be reissued after a source has been 790 * destroyed and therefore it is never valid to use this function with a 791 * source ID which may have already been removed. An example is when 792 * scheduling an idle to run in another thread with g_idle_add(): the 793 * idle may already have run and been removed by the time this function 794 * is called on its (now invalid) source ID. This source ID may have 795 * been reissued, leading to the operation being performed against the 796 * wrong source. 797 * 798 * Params: 799 * tag = the ID of the source to remove. 800 * 801 * Returns: %TRUE if the source was found and removed. 802 */ 803 public static bool remove(uint tag) 804 { 805 return g_source_remove(tag) != 0; 806 } 807 808 /** 809 * Removes a source from the default main loop context given the 810 * source functions and user data. If multiple sources exist with the 811 * same source functions and user data, only one will be destroyed. 812 * 813 * Params: 814 * funcs = The @source_funcs passed to g_source_new() 815 * userData = the user data for the callback 816 * 817 * Returns: %TRUE if a source was found and removed. 818 */ 819 public static bool removeByFuncsUserData(GSourceFuncs* funcs, void* userData) 820 { 821 return g_source_remove_by_funcs_user_data(funcs, userData) != 0; 822 } 823 824 /** 825 * Removes a source from the default main loop context given the user 826 * data for the callback. If multiple sources exist with the same user 827 * data, only one will be destroyed. 828 * 829 * Params: 830 * userData = the user_data for the callback. 831 * 832 * Returns: %TRUE if a source was found and removed. 833 */ 834 public static bool removeByUserData(void* userData) 835 { 836 return g_source_remove_by_user_data(userData) != 0; 837 } 838 839 /** 840 * Sets the name of a source using its ID. 841 * 842 * This is a convenience utility to set source names from the return 843 * value of g_idle_add(), g_timeout_add(), etc. 844 * 845 * It is a programmer error to attempt to set the name of a non-existent 846 * source. 847 * 848 * More specifically: source IDs can be reissued after a source has been 849 * destroyed and therefore it is never valid to use this function with a 850 * source ID which may have already been removed. An example is when 851 * scheduling an idle to run in another thread with g_idle_add(): the 852 * idle may already have run and been removed by the time this function 853 * is called on its (now invalid) source ID. This source ID may have 854 * been reissued, leading to the operation being performed against the 855 * wrong source. 856 * 857 * Params: 858 * tag = a #GSource ID 859 * name = debug name for the source 860 * 861 * Since: 2.26 862 */ 863 public static void setNameById(uint tag, string name) 864 { 865 g_source_set_name_by_id(tag, Str.toStringz(name)); 866 } 867 }